package com.from.menlo.park;


import java.util.Calendar;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.TableRow.LayoutParams;

public class CalendarActivity extends Activity{
	
	String TAG = "CalendarActivity";
	int noDays = 0;
	
	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);

		setContentView(R.layout.calendar_layout);

		TableLayout tl = (TableLayout)findViewById(R.id.myTableLayout);

		android.widget.TableLayout.LayoutParams lp = new TableLayout.LayoutParams(
				LayoutParams.FILL_PARENT,
				LayoutParams.WRAP_CONTENT);

		Calendar cal = Calendar.getInstance();
		cal.set(2011, Calendar.JANUARY, 1);
		noDays = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
		Log.v(TAG,"No of days = "+noDays);
		
		for(int i = 1;i<=noDays/6;i++){
			tl.addView(createRow(i),lp);
		}
	}


	public TextView createView(int days){

		TextView tv = new TextView(CalendarActivity.this);
		tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
				LayoutParams.WRAP_CONTENT));
		
			tv.setText(Integer.toString(days));
		
		return tv;
	}

	public TableRow createRow(int days){
		TableRow tr = new TableRow(CalendarActivity.this);

		tr.setLayoutParams(new LayoutParams(
				LayoutParams.FILL_PARENT,
				LayoutParams.WRAP_CONTENT));
		for(int i=0; i<=6;i++){
			tr.addView(createView(days+i));
		}
		return tr;
	}
}